module.exports = function ($scope, $modalInstance, FileUploader,$resource, $modal, item, flag, toaster){
    

  
   
    init();
    function init(){
        $scope.opeinfo = flag ? {'flag': true} : angular.copy(item);
        console.log($scope.opeinfo);
        if($scope.opeinfo.flag){
            searchtemplan();
        }else{
            searchtemplanbyid();
        }
        
    }
   
    //保存
    $scope.save = function (){
       
        var para = {
            'id' :  $scope.opeinfo.id,
            'travel_name' :  $scope.opeinfo.travel_name,
            'travel_address' : $scope.opeinfo.travel_address,
            'travel_license' :  $scope.opeinfo.travel_license,
            'travel_license_no' :  $scope.opeinfo.travel_license_no,
            'travel_legal_person_name' : $scope.opeinfo.travel_legal_person_name,
            'travel_legal_person_no' : $scope.opeinfo.travel_legal_person_no,
            'business_place' : $scope.opeinfo.business_place,
            'licensing_scope' : $scope.opeinfo.licensing_scope,
            'registered_capital' :  $scope.opeinfo.registered_capital,
            'setup_time' :  $scope.opeinfo.setup_time,
            'TEL' : $scope.opeinfo.TEL,
            'discipline_info' : $scope.opeinfo.discipline_info,
            'templan_id' : $scope.templan.id
        }
       
        $resource('/api/as/goc/peopeninfo/save', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    //查询模板
    function searchtemplan(){
        $resource('/api/as/goc/peopentemplan/getupInfo', {}, {}).save({}, function(res){
            if(res.errcode === 0){
                $scope.templan = res.data;
                if($scope.templan.num == 0){
                    $scope.templan.travel_name = 1;
                    $scope.templan.travel_address = 1;
                    $scope.templan.travel_license = 1;
                    $scope.templan.travel_license_no = 1;
                    $scope.templan.travel_legal_person_name = 1;
                    $scope.templan.travel_legal_person_no = 1;
                    $scope.templan.business_place = 1;
                    $scope.templan.licensing_scope = 1;
                    $scope.templan.registered_capital = 1;
                    $scope.templan.setup_time = 1;
                    $scope.templan.TEL = 1;
                    $scope.templan.discipline_info = 1;
                }
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
     //查询模板
     function searchtemplanbyid(){
        var para = {
            'id' :  $scope.opeinfo.templan_id
        }
        $resource('/api/as/goc/peopentemplan/getInfo', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.templan = res.data;
                if($scope.templan.num == 0){
                    $scope.templan.travel_name = 1;
                    $scope.templan.travel_address = 1;
                    $scope.templan.travel_license = 1;
                    $scope.templan.travel_license_no = 1;
                    $scope.templan.travel_legal_person_name = 1;
                    $scope.templan.travel_legal_person_no = 1;
                    $scope.templan.business_place = 1;
                    $scope.templan.licensing_scope = 1;
                    $scope.templan.registered_capital = 1;
                    $scope.templan.setup_time = 1;
                    $scope.templan.TEL = 1;
                    $scope.templan.discipline_info = 1;
                }
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }


    //通过
    $scope.agree = function (){
       if($scope.opeinfo.remark == undefined){
            toaster.error({title: '', body: '审核意见不可为空！'});
            remark;
        }
       
        var para = {
            'id' :  $scope.opeinfo.id,
            'remark' : $scope.opeinfo.remark
        }
       
        $resource('/api/as/goc/peopeninfo/updateagree', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '审核成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
   
     //不通过
     $scope.disagree = function (){
        if($scope.opeinfo.remark == undefined){
            toaster.error({title: '', body: '审核意见不可为空！'});
            remark;
        }
        var para = {
            'id' :  $scope.opeinfo.id,
            'remark' : $scope.opeinfo.remark
        }
       
        $resource('/api/as/goc/peopeninfo/updatedisagree', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '审核成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }


    //营业执照
    var uploader = $scope.uploader = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
    });

    uploader.filters.push({
        name: 'imageFilter',
        fn: function(item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });    
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
        $scope.opeinfo.travel_license = response.savename; 
        
    };


    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }
};